<?php
class cee{
	public $openid;
	public $openkey;
	public $pf;
	public $parameter;
	public $gp;
	public $openapi;
	//
	public function  __construct() {
		//if(empty($this->openid)||empty($this->openkey)||empty($this->pf)) exit('请从空间进入 ');
		require_once 'OpenApiV3.php';
        require_once 'Tencent.php';
		$this->openapi=new OpenApiV3('100656353', '52319b6d4abba9f236bc23f936d917b3');
		//测试
		//$this->openapi->setServerName('119.147.19.43');
		//$this->openapi->setServerName('1.254.254.22');
		$this->openapi->setServerName('1.254.254.23');
	}
	
	public function getuserinfo(){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		if($this->pf == "tapp"){
			$_SESSION['t_openid'] = $this->openid;
			$_SESSION['t_openkey'] = $this->openkey;
	
			OAuth::init('100656353', '52319b6d4abba9f236bc23f936d917b3');
			//验证授权
			$r = OAuth::checkOAuthValid();
			//var_dump($r);
			if($r){
				//用户已授权，获取用户信息
				$userinfo = json_decode(Tencent::api('user/info'),true);
				$userinfo['figureurl'] = $userinfo['data']['head']."/50";
				$userinfo['nickname'] = $userinfo['data']['nick'];
				$_SESSION['name'] = $userinfo['data']['name'];
			}else{
		        	die("未授权");
			}
		}else{
			$userinfo = $this->openapi->api('/v3/user/get_info',$this->gp);
		}
		if($userinfo['ret'] != 0) exit($userinfo['msg'].' | /v3/user/get_info');
		return $userinfo;
	}
	//v3/csec/word_filter
	public function getwordfilter($str){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		
		$this->gp = array_merge($this->gp,array('content'=>$str));
		//exit(json_encode($this->gp));
		$getwordfilter = $this->openapi->api('/v3/csec/word_filter',$this->gp);
		//exit(json_encode($getwordfilter));
		if($getwordfilter['ret'] != 0) {exit($getwordfilter['msg'].' | /v3/csec/word_filter');}
		elseif($getwordfilter['is_dirty']==1){
			$str=$getwordfilter['msg'];
		}
		
		return $str;
	}
	//v3/relation/get_app_friends
	public function getappfriends(){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		$appfriends = $this->openapi->api('/v3/relation/get_app_friends',$this->gp);
		if($appfriends['ret'] != 0) exit($appfriends['msg'].' | /v3/relation/get_app_friends');
		return $appfriends['items'];
	}
	public function isFansCee($qq){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		$this->gp = array_merge($this->gp,array('page_id'=>$qq));
		$isfans = $this->openapi->api('/v3/page/is_fans',$this->gp);
		if($isfans['ret'] != 0) exit($isfans['msg'].' | /v3/page/is_fans');
		return $isfans=$isfans['is_fans'];
	}
	//v3/user/get_multi_info
	public function getmultiinfo($fopenids){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		$this->gp = array_merge($this->gp,array('fopenids'=>$fopenids));
		$multiinfo = $this->openapi->api('/v3/user/get_multi_info',$this->gp);
		if($multiinfo['ret'] != 0) exit($multiinfo['msg'].' | /v3/user/get_multi_info');
		return $multiinfo['items'];
	}
	public function verifyInvkey($invkey, $itime, $iopenid){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf,'invkey'=>$invkey,'itime'=>$itime,'iopenid'=>$iopenid);
		$verifyInvkey_rs = $this->openapi->api('/v3/spread/verify_invkey',$this->gp);
		if($verifyInvkey_rs['ret']==0){
			return $verifyInvkey_rs['is_right'];
		}else{
			return -1;
		}
	}
	//v3/spread/is_reminder_set
	public function isreminderset(){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		$this->gp = array_merge($this->gp,array('cmd'=>2));
		$rs = $this->openapi->api('/v3/spread/is_reminder_set',$this->gp);
		if($rs['ret'] != 0) exit($rs['msg'].' | /v3/spread/is_reminder_set');
		return $rs;
	}
	//v3/spread/set_reminder
	public function setreminder(){
		$this->gp=array('openid'=>$this->openid,'openkey'=>$this->openkey,'pf'=>$this->pf);
		$this->gp = array_merge($this->gp,array('begin0'=>(time()+60),'key0'=>'0','type0'=>20001,'title0'=>'优品购物开拍啦,赶紧来竞拍吧'));
		$rs = $this->openapi->api('/v3/spread/set_reminder',$this->gp);
		if($rs['ret'] != 0) exit($rs['msg'].' | /v3/spread/set_reminder');
		return $rs;
	}
	//判断是否好友 >> ljanson   //B1084F5A5562977E35A68F527C0E6B72 客服openid
	public function is_friend(){
		$this->gp = array('openid'=>$this->openid, 'openkey'=>$this->openkey, 'pf'=>$this->pf, 'fopenid'=>'B1084F5A5562977E35A68F527C0E6B72');
		$rs = $this->openapi->api('/v3/relation/is_friend', $this->gp);
		if($rs['ret'] != 0) exit($rs['msg'].' | /v3/relation/is_friend');
		$is_friend = false;
		if($rs["ret"] == 0 && $rs["is_friend"] == 1){
			$is_friend = true;
		}
		return $is_friend;
	}
	//是否已经添加到面板 v3/spread/is_app_onpanel
	public function isMianban(){
	    $this->gp = array('openid'=>$this->openid, 'openkey'=>$this->openkey, 'pf'=>$this->pf);
	    $rs = $this->openapi->api('/v3/spread/is_app_onpanel', $this->gp);
	    /* if($rs['ret'] != 0) exit($rs['msg'].' | / v3/spread/is_app_onpanel');
	    $in_applist = 0;
	    if($rs["ret"] == 0 && $rs["in_applist"] == 1){
	        $in_applist = 1;
	    } */
	    return 1;//$in_applist;
	}
}